<?php
/**
 * Created by PhpStorm.
 * User: jifee8505
 * Date: 2018/1/23
 * Time: 上午11:28
 */

namespace backend\widgets;

use Yii;
use backend\models\messages\Message;
use backend\models\messages\MessageSearch;
use common\models\match\Match;
use yii\base\Widget;
use yii\base\InvalidConfigException;

/** <?= MatchMessageTable::widget(['model' => $model]) ?> */
class MatchMessageTable extends Widget
{
    public $model;

    public function init()
    {
        parent::init();

        if (empty($this->model)) {
            throw new InvalidConfigException('Required `model` param isn\'t set.');
        }
    }

    public function run()
    {
        $queryParams['MessageSearch'] = [
            'item_id' => $this->model->id,
            'class' => Match::className(),
        ];

        $model = new Message();
        $searchModel = new MessageSearch();
        $dataProvider = $searchModel->search($queryParams);

        return $this->render('match-message-table', [
            'model' => $model,
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
            'templates' => $model->getWechatTemplates()
        ]);
    }
}